﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>投料统计看板</title>
  <style>
    .card-header-title {
      font-size: 20px;
      font-weight: bold;
    }

    .el-form-item {
      margin-bottom: 5px;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <el-row class="header">
      <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
      <el-col :span="12" class="header-title" id="">{{title}}</el-col>
      <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
    </el-row>

    <div style="padding:5px;">
      <el-form :inline="true" :model="queryInfo" :label-position="'left'">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" filterable @change="factorySelectChange">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleBtnSearch" icon="el-icon-search" size="small">查询</el-button>
        </el-form-item>
      </el-form>

      <el-card>
        <div slot="header">
          <div class="card-header-title">分厂批次各等待时间明细信息</div>
        </div>
        <div>
          <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
            element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column label="件号" prop="productname" width="180" show-overflow-tooltip></el-table-column>
            <el-table-column label="名称" prop="productdescription" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="批次" prop="containerno" width="120" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="数量" prop="qty" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column label="开卡时间" prop="factorystartdate" width="120" :formatter="splitDate"></el-table-column>
            <el-table-column label="工艺确认等待时间" prop="gongyiwaittime" width="160" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag v-if='scope.row.gongyiwaittime > 1' type="danger">{{scope.row.gongyiwaittime}} 天</el-tag>
                <el-tag v-else>{{scope.row.gongyiwaittime}} 天</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="发料等待时间" prop="faliaowaittime" width="160" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag v-if='scope.row.faliaowaittime > 7' type="danger">{{scope.row.faliaowaittime}} 天</el-tag>
                <el-tag v-else>{{scope.row.faliaowaittime}} 天</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="到料等待时间" prop="daoliaowaittime" width="160" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag v-if='scope.row.daoliaowaittime > 1' type="danger">{{scope.row.daoliaowaittime}} 天</el-tag>
                <el-tag v-else>{{scope.row.daoliaowaittime}} 天</el-tag>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryInfo.currentPage" :page-sizes="[10,20,50,100]" :page-size="queryInfo.pageSize"
            layout="prev,pager,next,jumper,sizes,total" :total="total">
          </el-pagination>
        </div>
      </el-card>

      <el-card>
        <div slot="header">
          <div class="card-header-title">分厂各计划员完成情况</div>
        </div>
        <div>
          <div style="height: 250px;" id="chart"></div>
        </div>
      </el-card>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getFactory, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        queryInfo: {
          factoryid: '',
          factoryname: '',
          currentPage: 1,//当前页
          pageSize: 5//每页显示条数
        },
        currentTime: '',
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        userInfo: {},
        factoryList: [],
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' }
      },
      methods: {
        async getData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/PZTouLiaoDashBoard.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        async getEmployeeDelayInfo() {
          echarts.dispose(document.getElementById("chart"));
          let chart = echarts.init(document.getElementById('chart'));
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/PZTouLiaoDashBoard.ashx?action=getEmployeeCompleteInfo', {
            type: 'getEmployeeCompleteInfo',
            ...this.queryInfo
          })
          chart.hideLoading();

          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("chart"));
          chart = echarts.init(document.getElementById('chart'));

          let arrEmployee = [], arrInTimeJiaoDuiQty = [], arrDelayJiaoDuiQty = [], arrVeryDelayJiaoDuiQty = [],
            arrInTimeFaLiaoQty = [], arrDelayFaLiaoQty = [], arrVeryDelayFaLiaoQty = [],
            arrInTimeDaoLiaoQty = [], arrDelayDaoLiaoQty = [], arrVeryDelayDaoLiaoQty = [], arrTaskCount = [];
          for (const i of data) {
            arrEmployee.push(i.FULLNAME);
            arrInTimeJiaoDuiQty.push(i.inTimeJiaoDuiQty);
            arrDelayJiaoDuiQty.push(i.delayJiaoDuiQty);
            arrVeryDelayJiaoDuiQty.push(i.veryDelayJiaoDuiQty);
            arrInTimeFaLiaoQty.push(i.inTimeFaLiaoQty);
            arrDelayFaLiaoQty.push(i.delayFaLiaoQty);
            arrVeryDelayFaLiaoQty.push(i.veryDelayFaLiaoQty);
            arrInTimeDaoLiaoQty.push(i.inTimeDaoLiaoQty);
            arrDelayDaoLiaoQty.push(i.delayDaoLiaoQty);
            arrVeryDelayDaoLiaoQty.push(i.vertDelayDaoLiaoQty);
            arrTaskCount.push(i.taskCount);
          }

          let option = {
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'shadow'
              }
            },
            legend: {
              x: 'left',
              y: 10,
              textStyle: {
                fontSize: '14',
                fontWeight: 'bold'
              },
              data: ["待校对", '及时校对', '超期校对', '严重超期校对', '及时发料', '超期发料', '严重超期发料', '及时到料', '超期到料', '严重超期到料']
            },
            grid: {
              left: '1%',
              right: '1%',
              bottom: '3%',
              containLabel: true
            },
            xAxis: [
              {
                type: 'category',
                data: arrEmployee,
                axisLabel: {
                  show: true,
                  textStyle: {
                    color: '#000',
                    fontSize: '16',
                    fontWeight: 'bold'
                  }
                }
              }
            ],
            yAxis: [
              {
                type: 'value',
                axisLine: {
                  lineStyle: {
                    color: '#000',
                    width: '1'
                  }
                },
                splitLine: {
                  lineStyle: {
                    color: '#999',
                    type: 'dashed'
                  }
                },
                axisLabel: {
                  show: true,
                  textStyle: {
                    color: '#000',
                    fontSize: '14',
                    fontWeight: 'bold'
                  }
                }
              }
            ],
            series: [
              {
                name: '待校对',
                type: 'bar',
                barMaxWidth: 35,
                color: '#999',
                data: arrTaskCount,
                itemStyle: {
                  normal: {
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'top'
                    }
                  }
                }
              },
              {
                name: '及时校对',
                type: 'bar',
                stack: '工艺等待',
                barMaxWidth: 35,
                color: 'green',
                data: arrInTimeJiaoDuiQty,
                itemStyle: {
                  normal: {
                    label: {
                      show: true,
                      color: '#fff',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '超期校对',
                type: 'bar',
                stack: '工艺等待',
                barMaxWidth: 35,
                color: 'yellow',
                data: arrDelayJiaoDuiQty,
                itemStyle: {
                  normal: {
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '严重超期校对',
                type: 'bar',
                stack: '工艺等待',
                barMaxWidth: 35,
                color: 'red',
                color: 'red',
                data: arrVeryDelayJiaoDuiQty,
                itemStyle: {
                  normal: {
                    fontSize: '26',
                    label: {
                      show: true,
                      color: '#fff',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '及时发料',
                type: 'bar',
                stack: '发料等待',
                barMaxWidth: 35,
                color: '#32cd32',
                data: arrInTimeFaLiaoQty,
                itemStyle: {
                  normal: {
                    font: '12',
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '超期发料',
                type: 'bar',
                stack: '发料等待',
                barMaxWidth: 35,
                color: '#ffd700',
                data: arrDelayFaLiaoQty,
                itemStyle: {
                  normal: {
                    font: '12',
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '严重超期发料',
                type: 'bar',
                stack: '发料等待',
                barMaxWidth: 35,
                color: '#ff4500',
                data: arrVeryDelayFaLiaoQty,
                itemStyle: {
                  normal: {
                    font: '12',
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '及时到料',
                type: 'bar',
                stack: '到料等待',
                barMaxWidth: 35,
                color: '#228b22',
                data: arrInTimeDaoLiaoQty,
                itemStyle: {
                  normal: {
                    font: '12',
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '超期到料',
                type: 'bar',
                stack: '到料等待',
                barMaxWidth: 35,
                color: '#ff8c00',
                data: arrDelayDaoLiaoQty,
                itemStyle: {
                  normal: {
                    font: '12',
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}',
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              },
              {
                name: '严重超期到料',
                type: 'bar',
                stack: '到料等待',
                barMaxWidth: 35,
                color: '#ff6347',
                data: arrVeryDelayDaoLiaoQty,
                itemStyle: {
                  normal: {
                    font: '12',
                    label: {
                      show: true,
                      color: '#000',
                      fontWeight: 'bold',
                      position: 'inside',
                      //formatter: '{c}'
                      formatter: function (value) {
                        if (value.data < 1) {
                          return "";
                        } else {
                          value.data;
                        }
                      }
                    }
                  }
                }
              }
            ]
          };

          chart.setOption(option);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        handleBtnSearch() {
          this.getData();
          this.getEmployeeDelayInfo();
        },
        factorySelectChange(val) {
          if (val) {
            this.queryInfo.factoryname = this.factoryList.filter(item => item.factoryid === val)[0].factoryname
          }
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        this.factoryList = await getFactory();

        if (this.userInfo.factoryid && this.factoryList.some(item => item.factoryid === this.userInfo.factoryid)) {
          const { factoryid, factoryname } = this.userInfo;
          this.queryInfo.factoryid = factoryid
          this.queryInfo.factoryname = factoryname
        } else {
          this.queryInfo.factoryid = this.factoryList[0].factoryid;
          this.queryInfo.factoryname = this.factoryList[0].factoryname;
        }
        this.getData();
        this.getEmployeeDelayInfo();
      },
      computed: {
        title() {
          return this.queryInfo.factoryname + '投料统计看板'
        }
      }
    })
  </script>
</body>

</html>